package pack.help;

public class Vec {
	public float x;
	public float y;
	
	public Vec add(float deltaX, float deltaY){
		x+=deltaX;
		y+=deltaY;
		return this;
	}
	
	public Vec addNR(float deltaX, float deltaY){
		return new Vec(x+deltaX,y+deltaY);
	}
	
	public Vec multiply(float c){
		x*=c;
		y*=c;
		return this;
	}
	
	// get a multiplied vector WITHOUT updating the vector
	public Vec multiplyNR(float c){
		return new Vec(x*c,y*c);
	}
	
	public static float angleBetween(Vec a,Vec b){
		float angle = 0;
		
		Vec X = a.getNormalized();
		Vec Y = b.getNormalized();
		// Get the dot product which gives the angle between 0 and PI, 
		// and get the sign from the sign of the Z coordinate of the cross product
		angle = (float) (Math.acos(X.x*Y.x+X.y*Y.y)*Math.signum(X.x*Y.y-X.y*Y.x));
		//angle = (float) (Math.acos(X.x*Y.x+X.y*Y.y)*Math.signum(X.y*Y.x-X.x*Y.y));
		return angle;
	}
	
	public Vec getNormalized(){
		float l = this.length();
		return new Vec(x/l,y/l);
	}
	
	public float length(){
		return (float) Math.sqrt(x*x+y*y);
	}
	
	public Vec add(Vec v){
		x+=v.getX();
		y+=v.getY();
		return this;
	}
	
	public Vec addNR(Vec v) {
		return new Vec(x+v.getX(),y+v.getY());
	}
	
	public float getX() {
		return x;
	}
	public void setX(float x) {
		this.x = x;
	}
	public float getY() {
		return y;
	}
	public void setY(float y) {
		this.y = y;
	}
	
	public static Vec subTract(Vec a, Vec b){
		return new Vec(a.x-b.x,a.y-b.y);
	}
	
	public Vec(float x, float y){
		this.x = x;
		this.y = y;
	}
	
	public Vec(Vec v){
		x = v.getX();
		y = v.getY();
	}

	public Vec(double x, double y) {
		this.x = (float) x;
		this.y = (float) y;
	}

	
}
